#!/usr/bin/python
import sys, os, tarfile, time, datetime, stat, glob

path = sys.argv[1]
prefix = sys.argv[2]

os.chdir(path)

today = datetime.date.today().strftime('%Y%m%d')
filename = prefix + "_" + today + ".tgz"

print "Creating ", filename

print "Compressing ..."

tar = tarfile.open(filename,"w:gz")

for name in glob.glob("./*.log*"):
    try:
        st = os.stat(name)
        if (stat.S_ISREG(st.st_mode)):
            lastmod_date = time.strftime('%Y%m%d',time.localtime(st[8]))
            if ( lastmod_date < today ):
                tar.add(name)
                os.remove(name)    
    except os.error:
        continue

tar.close();

print "Done."